package com.fc.test.api;

import com.fc.test.model.auto.TAbbQuanmin;
import com.fc.test.service.TAbbQuanminService;
import com.fc.test.util.JsonUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping(value = "/apiQuanminController")
@Api(value = "全民推广")
public class ApiQuanminController {

    @Autowired
    private TAbbQuanminService quanminService;

    @ResponseBody
    @PostMapping(value="getQuanminByPage",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "分页查询全民推广")
    public String getQuanminByPage(
            @ApiParam(value = "页码") @RequestParam(value = "page") int page,
            @ApiParam(value = "用户id") @RequestParam(value = "memberId") String memberId
    ){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbQuanmin> list = quanminService.getQuanminByPage(page,memberId);
        if(list.size()>0){
            resMap.put("msg","获取全民推广列表成功");
        }else{
            resMap.put("msg","到底了");
        }
        resMap.put("list",list);
        resMap.put("success",true);
        return JsonUtil.jsonMapStr(resMap);
    }


    @ResponseBody
    @PostMapping(value="releaseQuanmin",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "发布全民推广")
    @ApiImplicitParams({
            @ApiImplicitParam(name="userid",value = "发布人id",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "price", value = "红包金额", dataType = "Double",paramType = "query"),
            @ApiImplicitParam(name = "zhuantimes", value = "转发次数", dataType = "Integer",paramType = "query"),
            @ApiImplicitParam(name="title",value = "标题",dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "introduction", value = "信息内容", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "images", value = "图片", dataType = "String",paramType = "query"),
            @ApiImplicitParam(name = "link", value = "商品或活动链接", dataType = "String",paramType = "query")
    })
    public String releaseQuanmin(String userid,double price,int zhuantimes,String title,String introduction,String images,String link ){
        Map<String,Object> resMap = new HashMap<>();
        TAbbQuanmin tAbbQuanmin = new TAbbQuanmin();
        tAbbQuanmin.setUserid(userid);
        tAbbQuanmin.setPrice(price);
        tAbbQuanmin.setZhuantimes(zhuantimes);
        tAbbQuanmin.setTitle(title);
        tAbbQuanmin.setIntroduction(introduction);
        tAbbQuanmin.setImages(images);
        tAbbQuanmin.setLink(link);

        resMap = quanminService.releaseQuanmin(tAbbQuanmin);
        return JsonUtil.jsonMapStr(resMap);
    }


    @ResponseBody
    @PostMapping(value="getQuanminDetail",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "全民推广详情")
    public String getQuanminDetail(
            @ApiParam(value = "全民推广id") @RequestParam(value = "qmid") String  qmid,
            @ApiParam(value = "用户id") @RequestParam(value = "userid") String userid
    ){
        Map<String,Object> resMap = quanminService.getQuanminDetail(qmid,userid);
        return JsonUtil.jsonMapStr(resMap);
    }

    @ResponseBody
    @PostMapping(value="getQuanminRedPcket",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "全民推广红包")
    public String getQuanminRedPcket(
            @ApiParam(value = "全民推广id") @RequestParam(value = "qmid") String  qmid,
            @ApiParam(value = "用户id") @RequestParam(value = "userid") String userid
    ){
        Map<String,Object> resMap = quanminService.getQuanminRedPcket(qmid,userid);
        return JsonUtil.jsonMapStr(resMap);
    }

    @ResponseBody
    @PostMapping(value="getMyQuanminList",produces = {"application/json; charset=utf-8"})
    @ApiOperation(value = "我发布的全民推广")
    public String getMyQuanminList(
            @ApiParam(value = "页码") @RequestParam(value = "page") int page,
            @ApiParam(value = "用户id") @RequestParam(value = "userid") String  userid
    ){
        Map<String,Object> resMap = new HashMap<>();
        List<TAbbQuanmin> list = quanminService.getMyQuanminList(page,userid);
        if(list.size()>0){
            resMap.put("msg","获取我发布的全民推广成功");
        }else{
            resMap.put("msg","到底了");
        }
        resMap.put("list",list);
        resMap.put("success",true);
        return JsonUtil.jsonMapStr(resMap);
    }
}
